/*
* Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: btclient.h.
*/

#ifndef BTCLIENT_H
#define BTCLIENT_H

#include <qmobilityglobal.h>

#include <QtCore/QObject>

QTM_BEGIN_NAMESPACE
class QBluetoothAddress;
class QBluetoothSocket;
QTM_END_NAMESPACE

QTM_USE_NAMESPACE

//! Bluetooth client class.
/*!
  This class creates a Bluetooth socket, which works as a client in a Bluetooth
  connection between two devices. The socket connects to the Bluetooth service by
  using the address and port, on which the remote server is listening.
*/
class BtClient : public QObject
{
    Q_OBJECT

public:
    //! Constructor.
    explicit BtClient(QObject *parent = 0);

    //! Destructor.
    virtual ~BtClient();

    //! Connects the Bluetooth socket to a remote service as a client.
    /*!
      \param address The Bluetooth address of the remote device.
      \param port The port on which the remote server is listening.
      \sa closeClient()
    */
    void startClient(const QBluetoothAddress &address, quint16 port);

    //! Disconnects the client from the Bluetooth service.
    /*!
      \sa startClient()
     */
    void closeClient();

    //! Sends data to remote device.
    /*!
      \param sharedData A byte array which contains the data to be sent.
      \sa startClient()
     */
    void writeSocket(const QByteArray &sharedData);

private Q_SLOTS:
    //! Reads the received data.
    void readSocket();

    //! Client successfully connected to Bluetooth service.
    void handleConnected();

Q_SIGNALS:
    //! Signalled when Bluetooth connection is successfully established.
    /*!
      \param remoteName The name of the remote device.
      \sa startClient()
     */
    void connected(const QString &remoteName);

    //! Signalled when Bluetooth connection is closed.
    /*!
      \sa stopClient()
     */
    void connectionClosed();

    //! Signalled when data is received from remote device.
    /*!
      \param message A byte array which contains the received data.
     */
    void messageReceived(const QByteArray &message);

private:
    QBluetoothSocket *m_socket; //!< Bluetooth socket.
};

#endif // BTCLIENT_H
